package com.gl.web;

import com.gl.common.utils.Result;
import com.gl.config.CustomProperties;
import com.gl.service.IFirstService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>Description:</p>
 *
 * @author gaol
 * @version 1.0
 * @date 2017/5/12
 */
@RestController
public class FirstController extends BaseController {


    @Autowired
    @Qualifier("secondService")
    private IFirstService firstService;
    /**
     * 自定义属性用法一
     */
    @Autowired
    private CustomProperties customProperties;
    /**
     * 自定义属性用法二
     * application.properties配置文件必须在目录resources下
     */
    @Value(value = "${custom.name}")
    private String name;

    /**
     * 异常测试
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/first", method = RequestMethod.GET)
    public Result frist() throws Exception {
        firstService.println();
        return new Result();
    }

    /**
     * 自定义属性
     *
     * @return
     */
    @RequestMapping(value = "/custom", method = RequestMethod.GET)
    public Result customProperties() {
        logger.info("获取自定义属性方法一：{}", customProperties.getName());
        logger.info("获取自定义属性方法二：{}", name);
        return new Result(name);
    }

    /**
     * Aop web访问日志
     *
     * @param name
     * @param flag
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/pointcut", method = RequestMethod.GET)
    public Result pointcut(String name, int flag) throws Exception {
        return new Result("成功");
    }

}
